Skip to content

Conversation

@legendecas
Copy link
Member

Derived classes' fields are already destroyed if the virtual methods are
invoked in the base class's destructor. It is not safe to call virtual
methods in base's dtor.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/node-api

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Aug 28, 2022
@bnoordhuis
Copy link
Member

Maybe I'm missing something but FinalizeAll() isn't virtual and neither does it call, directly or indirectly, virtual methods - or does it?

@legendecas
Copy link
Member Author

legendecas commented Aug 28, 2022

Maybe I'm missing something but FinalizeAll() isn't virtual and neither does it call, directly or indirectly, virtual methods - or does it?

FinalizeAll invokes each RefTrackers Finalize, which eventually invokes env's virtual CallFinalizer method, like in RefBase::Finalize.

virtual ~napi_env__() { FinalizeAll(); }
v8::Isolate* const isolate; // Shortcut for context()->GetIsolate()
v8impl::Persistent<v8::Context> context_persistent;
virtual ~napi_env__() = default;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe try if you can make the constructor protected, to avoid callers deleting it without proper cleanup.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense to me. Thank you for the suggestion! Updated.

Derived classes' fields are already destroyed if the virtual methods are
invoked in the base class's destructor. It is not safe to call virtual
methods in base's dtor.
@legendecas legendecas force-pushed the node-api/dtor-virtual branch from e2d1c39 to dd48302 Compare August 28, 2022 13:43
@legendecas legendecas added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 28, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 28, 2022
@nodejs-github-bot
Copy link
Collaborator

@legendecas legendecas added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Aug 29, 2022
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@legendecas legendecas added the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 31, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 31, 2022
@nodejs-github-bot nodejs-github-bot merged commit ad3c7bc into nodejs:main Aug 31, 2022
@nodejs-github-bot
Copy link
Collaborator

Landed in ad3c7bc

@legendecas legendecas deleted the node-api/dtor-virtual branch August 31, 2022 13:47
@juanarbol juanarbol mentioned this pull request Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants